package com.daiqee.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.daiqee.pojo.GoodsList;
import com.daiqee.pojo.StoragePosition;
import com.daiqee.dao.mapper.StoragePositionMapper;
/**
 * 货架
 * 
 * <br/>
 * @since JDK 1.8
 * @version  V2.1
 * @author RichardTang 
 * @date: 2018年5月8日 上午8:27:38
 * @package com.daiqee.service.impl
 * @copyright:Copyright (c) 2018, 1245811923@qq.com All Rights Reserved.
 */
@Service
public class StoragePositionService extends ServiceImpl<StoragePositionMapper, StoragePosition>{

	@Autowired
	private GoodsListService goodsListService;
	
	@Autowired
	private StoragePositionMapper storagePositionMapper;

	/**
	 * 校验该货架下是否有货物 无货物才删除
	 * 
	 * @param idList
	 * 			要删除的id号
	 * 
	 * @return true:删除成功 false:删除失败
	 */
	public Boolean checkDeleteByIds(List<String> idList) {
		
		int resultNum = 0;
		
		//查询 当前需要删除的货架 下的货物条数
		int goodsCount = goodsListService.selectCount(
		    new EntityWrapper<GoodsList>().in("goods_list_storage_id", idList)
		);
		
		if(goodsCount < 0) {
			resultNum = storagePositionMapper.deleteBatchIds(idList);
			return resultNum > 0 ? true : false;
		}else {
			return false;
		}
	}
}
